package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import pojo.Area;
import util.DBUtil;
import dao.AreaDao;

public class AreaDaoImpl implements AreaDao{

	@Override
	public List<Area> findByArea(String areaName) {
	
			List<Area> list=new ArrayList<Area>();
			String sql = "select * from area where area like ?";
			Connection con=DBUtil.createConnection();
			PreparedStatement ps = null;
			ResultSet rs =null;
			Area area=null;
			try {
				ps=con.prepareStatement(sql);
				ps.setString(1, areaName+"%");
				rs=ps.executeQuery();
				while(rs.next())
				{
					area = new Area();
					area.setId(rs.getInt(1));
					area.setAreaid(rs.getString(2));
					area.setArea(rs.getString(3));
					area.setCityid(rs.getString(4));
					list.add(area);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			finally{
				DBUtil.close(rs, null,ps );
			}
			return list;
	}

}
